<script type="text/javascript">
	var minuteBonus = {$settings.minuteBonus};
	var minutePrice =  {$settings.minutePrice};
	
	$(document).ready(function () {$smarty.ldelim}

		$('.textMinutes').blur(function () {$smarty.ldelim}
			
			var newValue = parseFloat($(this).val());
			var oldValue = parseFloat($(this).attr('data-currentValue'));
			if(newValue != oldValue) {$smarty.ldelim}
				var operationId = $(this).attr('data-operationId');
				var oldTotal = parseFloat($("#totalMinutes").text());	
				
				var newTotal = oldTotal + (newValue - oldValue);
				
				var newBonus = new Number(newValue * (1 + ( minuteBonus / 100 )));
				var newPrice = new Number(newValue * (1 + ( minuteBonus / 100 )) * minutePrice);
				
				var newBonusTotal = new Number(newTotal * (1 + ( minuteBonus / 100 )));
				var newPriceTotal = new Number(newTotal * (1 + ( minuteBonus / 100 )) * minutePrice);
				
				$("#bonus"+operationId).text(newBonus.toFixed(2));
				$("#price"+operationId).text(newPrice.toFixed(4));
				
				$("#totalMinutes").text(newTotal);
				$("#totalBonus").text(newBonusTotal.toFixed(2));
				$("#totalPrice").text(newPriceTotal.toFixed(4));
				
				$(this).attr('data-currentValue', newValue);
			{$smarty.rdelim}
		{$smarty.rdelim});
		
	{$smarty.rdelim});
</script>

						<h1 align="center">Операции</h1>
						<h2 align="center">Модел: {'cp1251'|iconv:'utf-8':$model->number()}. {'cp1251'|iconv:'utf-8':$model->name()}</h2>

					{if isset($operator)}
						<p align="center">Добавяне операции за оператор: <b>{'cp1251'|iconv:'utf-8':$operator->name()}</b></p>
						<p align="center">Дата: {$dateEdit}</p>
					{else}
						<form name="formModel" action="{$smarty.server.PHP_SELF}" method="post">
							<table cellspacing="0" cellpadding="2">
								<tr>
									<td colspan="3"><h3><b>Добавяне на нова Операция</h3></b></td>
								</tr>
								<tr>
									<td>Номер</td>
									<td>Име</td>
									<td>Минути</td>
									<td>&nbsp;</td>
								</tr>
									<tr>
										<td><input type="text" size="6" name="number" /></td>
										<td><input type="text" size="60" name="name" /></td>
										<td><input type="text" size="6" name="minutes" /></td>
										<!-- <td><input type="text" size="6" name="price" /></td> -->
										
										
										<td>
											<input type="submit" name="sub_operation" value="Запази" />
											<input type="hidden" name="modid" value="{$smarty.get.modid}" />
										</td>
									</tr>
								</table>
							</form>
						{/if}

						<br /><br />
						<input type="button" value="Изработени" onclick="document.location='{$smarty.server.PHP_SELF}?modid={$smarty.get.modid}&mode=work_count'" />
						<input type="button" value="Заработка (НОВО)" onclick="document.location='model_work.php?modid={$smarty.get.modid}&mode=work_count'" />
						<br /><br />

						<table cellspacing="0" width="100%">
							<tr>
								<td class="DialogTitle">Операции</td>
							</tr>
							<tr>
								<td class="DialogBorder">
						
									<table cellspacing="1" class="DialogBox">
										<tr>
											<td class="DialogBox" valign="top"><br />
												<form action="{$smarty.server.PHP_SELF}?modid={$smarty.get.modid}" method="post" name="procoperform">

												{*if $vsdeDate*}
												{if isset($operator)}
													<input type="hidden" name="vsdeDate" id="vsdeDate" value="{$vsdeDate}" />
													<input type="hidden" name="modid" value="{$smarty.get.modid}" />
													<input type="hidden" name="opid" value="{$operator->id()}" />
												{/if}

													<input type="hidden" name="mode" value="" />

													<script src="{$wwwDir}js/change_all_checkboxes.js" language="JavaScript" type="text/javascript"></script>
													<div style="line-height: 170%;">
														<a href="javascript: checkAll(true, document.procoperform, 'opids');">Всички</a> / 
														<a href="javascript: checkAll(false, document.procoperform, 'opids');">Нищо</a>
													</div>

													<table cellpadding="2" cellspacing="1" width="70%">
														<tr class="TableHead">
														{if isset($operator)}
															<td width="15%">Брой</td>
														{else}
															<td width="3%">&nbsp</td>
														{/if}
															<td width="5%">Номер</td>
															<td >Име</td>
															<td width="5%">Минути</td>
															<td width="5%">Минути + {$settings.minuteBonus}%</td>
															<td width="5%">Минути * {$settings.minutePrice} лв.</td>
															<!-- 
															<td width="5%">Цена (старо)</td>
															 -->
														</tr>

													{foreach from=$listOperations item=op}
														<tr {cycle values=",class='TableSubHead'"}>
															<td>
																<input type="checkbox" name="opids[{$op->id()}]" />
															{if isset($operator)}
																<input type="text" name="posted_data[{$op->id()}][count]" size="4"/>
																<input type="hidden" name="posted_data[{$op->id()}][price]" size="4"/>
															{/if}
															</td>
															<td >
																<input type="text" size="4" name="posted_data[{$op->id()}][number]" value="{'cp1251'|iconv:'utf-8':$op->number()}" />
															</td>
															<td>
																<font class="ItemsList">
																	<input type="text" size="60" name="posted_data[{$op->id()}][name]" value="{'cp1251'|iconv:'utf-8':$op->name()}" />
																</font>
															</td>
															
															
														{if isset($operator)}
															<td></td>
															<td></td>
															
															<td>{$op->priceByMinutes()}</td>
															<!-- 
															<td>{$op->price()}</td>
															 -->
														{else}
															<td><input class="textMinutes" type="text" name="posted_data[{$op->id()}][minutes]" value="{$op->minutes()}" data-currentValue="{$op->minutes()}" data-operationId="{$op->id()}" size="6"/></td>
															
															<td id="bonus{$op->id()}">{math equation="x * (1 + ( y / 100 ) )" x=$op->minutes() y=$settings.minuteBonus format="%.2f"}</td>
															<td id="price{$op->id()}">{math equation="(x * (1 + ( y / 100 )) * z )" x=$op->minutes() y=$settings.minuteBonus z=$settings.minutePrice format="%.4f"}</td>
															<!-- 
															<td><input type="text" name="posted_data[{$op->id()}][price]" value="{$op->price()}" size="6"/></td>
															 -->
														{/if}
															
															
														</tr>
													{/foreach}
														<tr>
															<td colspan="6"><hr /></td>
														</tr>
													{if !isset($operator)}
														<tr>
															<td colspan="3" align="right">Общо:</td>
															<td id="totalMinutes">{$modelMinutes}</td>
															<td id="totalBonus">{math equation="x * (1 + ( y / 100 ) )" x=$modelMinutes y=$settings.minuteBonus format="%.2f"}</td>
															<td id="totalPrice">{math equation="(x * (1 + ( y / 100 )) * z )" x=$modelMinutes y=$settings.minuteBonus z=$settings.minutePrice format="%.4f"}</td>
															<!-- 
															<td id="totalPrice">{$modelPrice}</td>
															 -->
														</tr>
													{/if}
														<tr>
															<td colspan="7"><hr /></td>
														</tr>
														<tr>
															<td colspan="7">
															{if isset($operator)}
																<input type="submit" name="submitAddWork" value="Запази"  />
															{else}
																<p align="center">
																	<input type="checkbox" name="change_work" />
																		За периода от {$fromDateEdit}    до {$toDateEdit}
																</p>
						
																<input type="hidden" name="fromVsdeDate" id="fromVsdeDate" value="{$fromVsdeDate}" />
																<input type="hidden" name="toVsdeDate" id="toVsdeDate" value="{$toVsdeDate}" />
																
																<input type="button" value="Смяна на Имена" onClick="this.form.mode.value='change_names'; this.form.submit();" />
																<input type="submit" name="sub_operations" value="Смяна на Цени"  />
																<input type="submit" name="del_operations" value="Изтриване" onClick="return confirm('Наистина ли искате да изтриете маркираните Операции?');" />
															{/if}
															</td>
														</tr>


													</table>
												</form>
												<br />&nbsp;
											</td>
										</tr>
										<tr>
											<td>{$pager}</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>


